<template>
	<el-dialog title="添加环境" :visible.sync="dialogVisible" width="800" @close="handleClose"
		:close-on-click-modal="false">
		<div slot="title" class="dialog-header-title">
			<i class="el-icon-edit-outline"></i>
			<span>添加环境</span>
		</div>

		<div class="smp-search">
			<el-form :inline="false" label-width="100px" size="mini" ref="form" :model="form" :rules="rules">

				<el-row>
					<el-col :span="24">
						<el-col :span="24">
							<el-form-item label="所属系统:" prop="systemNo">
								<el-input v-model="form.systemNo" placeholder="所属系统"></el-input>
							</el-form-item>
						</el-col>

						<el-col :span="24">
							<el-form-item label="系统环境IP:" prop="addr">
								<el-input v-model="form.addr" placeholder="系统环境IP"></el-input>
							</el-form-item>
						</el-col>
						
						<el-col :span="24">
							<el-form-item label="系统端口:" prop="port">
								<el-input v-model="form.port" placeholder="系统端口"></el-input>
							</el-form-item>
						</el-col>
						
						<el-col :span="24">
							<el-form-item label="系统URL:" prop="url">
								<el-input v-model="form.url" placeholder="系统URL" required="false"></el-input>
							</el-form-item>
						</el-col>
						
						<el-col :span="24">
							<el-form-item label="ESB环境IP:" prop="esbaddr">
								<el-input v-model="form.esbaddr" placeholder="ESB环境IP"></el-input>
							</el-form-item>
						</el-col>

						<el-col :span="24">
							<el-form-item label="环境类型:" prop="envirType">
								<el-select v-model="form.envirType" style="width: 100%" placeholder="环境类型">
									<el-option v-for="item in dict('SMP0011')" :key="item.itemCode"
										:label="item.itemName" :value="item.itemCode">
									</el-option>
								</el-select>
							</el-form-item>
						</el-col>

						<el-col :span="24">
							<el-form-item label="备注:" prop="remark">
								<el-input v-model="form.remark" placeholder="备注" required="false"></el-input>
							</el-form-item>
						</el-col>

					</el-col>
				</el-row>


			</el-form>
		</div>
		<span slot="footer" class="dialog-footer">
			<el-button size="mini" type="primary" @click="onSubmit">提交</el-button>
			<el-button size="mini" @click="reset">清空</el-button>
			<el-button size="mini" @click="closeDialog">取消</el-button>
		</span>
	</el-dialog>
</template>

<script>
	"use strict";
	import {
		addEnvironmentInfo
	} from '@/api/environment.js';

	export default {
		/* name:'Add', */

		data() {
			return {
				dialogVisible: false,
				rules: {
					systemNo: [{
						required: true,
						message: "所属系统不能为空",
						trigger: ['blur', 'change']
					}],
					addr: [{
						required: true,
						message: "系统环境IP不能为空",
						trigger: ['blur', 'change']
					}],
					port: [{
						required: true,
						message: "系统端口不能为空",
						trigger: ['blur', 'change']
					}],
					esbaddr: [{
						required: true,
						message: "ESB环境IP不能为空",
						trigger: ['blur', 'change']
					}],
					envirType: [{
						required: true,
						message: "环境类型不能为空",
						trigger: ['blur', 'change']
					}],
				},
				form: {
					systemNo: '',
					addr: '',
					port: '',
					url: '',
					esbaddr: '',
					envirType: '',
					remark: ''
				},

			};
		},



		methods: {

			onSubmit() {
				this.addEnvironmentInfo();
			},

			reset() {
				this.form = {};
				this.$refs["form"].resetFields();
			},

			addEnvironmentInfo() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						addEnvironmentInfo(this.form).then(response => {
							this.data = response.data.extend;
							this.$message({
						duration:5000,
								type: 'success',
								message: '添加环境成功！'
							});
							this.form = {};
							this.$refs["form"].resetFields();
							this.dialogVisible = false;
							this.$emit("onSubmit");
						}).catch(error => {
							this.$message({
						duration:5000,								type: 'error',
								message: '添加环境失败！'
							});
							this.form = {};
							this.$refs["form"].resetFields();
							this.dialogVisible = false;
							this.$emit("onSubmit");
						});
					}
				})

			},

			showDialog() {
				this.dialogVisible = true;
			},

			closeDialog() {
				this.$refs["form"].resetFields();
				this.dialogVisible = false;
			},

			handleClose() {
				this.$refs["form"].resetFields();
				this.dialogVisible = false;
			}


		},

	}
</script>

<style>
</style>
